#include <bits/stdc++.h>
using namespace std;
const int MAX = 5010;
struct Goods
{
    int value, pieces;
} G[MAX];
bool cmps(const Goods &g1, const Goods &g2){
    if(g1.value == g2.value) return g1.pieces > g2.pieces;
    return g1.value < g2.value;
}
int main(void)
{
    int n, m;
    long sum = 0;
    scanf("%d %d", &n, &m);
    for(int i = 0; i<m; i++){
        scanf("%d %d",&G[i].value,&G[i].pieces);
    }
    sort(G,G+m,cmps);
    for(int i = 0; ;i++){
        if(G[i].pieces <= n){
            sum += G[i].pieces*G[i].value;
            n -= G[i].pieces;
        }else{
            sum += n * G[i].value;
            n = 0;
        }
        if(n == 0) break;
    }
    cout<<sum;
    return 0;
}